﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PSE.Communication.Fix.Common;
using System.Threading;

namespace PSE.Communication.Fix.Client
{
    /// <summary>
    /// Classe responsável expor as mensagem do protocolo fix do tipo Execution Report
    /// </summary>
    public class ExecutionReportClient
    {
        private IRepositoryProvider _repositoryProvider;
        private IFixModelConverter<ExecutionReportEntity> _converter;

        public ExecutionReportClient()
        {
            _repositoryProvider = RepositoryManager.GetRepositoryProvider();
            _converter = ConverterFactory.GetModelConverter<ExecutionReportEntity>();
        }

        public List<ExecutionReportEntity> ListExecutionReportMessages(int length, int companyId)
        {
            return ListExecutionReportMessages(length, companyId, -1, DateTime.MinValue);
        }

        public List<ExecutionReportEntity> ListExecutionReportMessages(int length, int companyId, long startId)
        {
            return ListExecutionReportMessages(length, companyId, startId, DateTime.MinValue);
        }

        public List<ExecutionReportEntity> ListExecutionReportMessages(int length, int companyId, DateTime receiveDate)
        {
            return ListExecutionReportMessages(length, companyId, -1, receiveDate);
        }

        public List<ExecutionReportEntity> ListExecutionReportMessages(int length, int companyId, long startId, DateTime receiveDate)
        {
            RepositoryParameter parameter = new RepositoryParameter();

            parameter.Length = length;
            parameter.CompanyId = companyId;
            parameter.MessageType = MessageType.ExecutionReport;

            if (startId >= 0)
                parameter.StartId = startId;

            if (receiveDate != DateTime.MinValue)
                parameter.ReceiveDate = receiveDate;

            return _converter.ConvertTo(_repositoryProvider.Read(parameter));
        }
    }
}